from tortoise import fields, models


class Address(models.Model):
    id = fields.IntField(pk=True)
    # 新增：关联用户，外键指向 User 模型
    user = fields.ForeignKeyField("models.User", related_name="addresses")  
    name = fields.CharField(max_length=255)  # 收货人姓名
    phone = fields.CharField(max_length=20)  # 收货人电话
    address = fields.CharField(max_length=255)  # 详细地址
    is_default = fields.BooleanField(default=False)  # 是否默认地址
    created_at = fields.DatetimeField(auto_now_add=True)  # 地址创建时间
    updated_at = fields.DatetimeField(auto_now=True)  # 地址更新时间

    class Meta:
        table = "address"